(function(angular) {
	'use strict';
	angular.module('fs.waf').controller('cda.currency.deleteRejectController', deleteRejectController);
	deleteRejectController.$inject = [ '$scope', 'Constants', 'modalService', 'gridService', 'layoutConfig', 'validatorConfig', 'authService',
			'currencyService' ];
	function deleteRejectController($scope, Constants, modalService, gridService, layoutConfig, validatorConfig, authService, currencyService) {
		var ctrl = this, currencyInfo = $scope.$stateParams.params, errorMessage = {};
		ctrl.layoutConfig = layoutConfig;
		ctrl.validatorConfig = validatorConfig;
		ctrl.currency = {};
		ctrl.init = function() {
			var params = {
					ccy : currencyInfo.ccy
			};
			authService.deleteReject($scope.$stateParams.params).then(function(response) {
				ctrl.currency = response.data.model || {};
				ctrl.currency.taskId = response.data.task.taskId;
				
			});
		};

		ctrl.deleteRejectSubmit = function() {
			modalService.openConfirmDialogs({
				'messages' : {msg : 'title.dialog.confirm.delete', args : [ctrl.currency.primaryKey]},
				'btnCallback' : {					
					"ok" : function(response){
						 authService.deleteRejectSubmit(ctrl.currency).then(submitSuccessful, submitFailed);
					}
				}
			});
		};
		
		ctrl.deleteRejectCancel = function() {
			modalService.openConfirmDialogs({
				'messages' : [ {msg : 'title.dialog.confirm.cancel', args : [ctrl.currency.primaryKey]} ],
				'btnCallback' : {
					'ok' : function(response) {
						authService.deleteRejectCancel(ctrl.currency).then(cancelSuccessful, cancelFailed);
					}
				}
			});
		};
		
		function rowSelectionChanged(eventRow, selectedRows) {
			ctrl.selectedSubCommpanyList = selectedRows;
		}

		function submitSuccessful(response) {
			modalService.openAcknowledgeDialogs({
				'messages' : [ 'title.dialog.successful.delete' ],
				'btnCallback' : {
					'close' : function() {
						$scope.go('cda.workflow.wfSetup.list');
					}
				},
				'redirections' : [ {
					'name' : 'title.infobar.workflow.list',
					'state' : 'cda.workflow.wfSetup.list',
					'params' : {}
				}, {
					'name' : 'title.infobar.currency.list',
					'state' : 'cda.currency.list',
					'params' : {}
				}]
			});
		}

		function submitFailed(response) {
			modalService.openErrorDialogs({
				'messages' : response.error
			});
		}

		function cancelSuccessful(response) {
			modalService.openAcknowledgeDialogs({
				'messages' : [ 'title.dialog.successful.cancel' ],
				'btnCallback' : {
					'close' : function() {
						$scope.go('cda.workflow.wfSetup.list');
					}
				},
				'redirections' : [ {
					'name' : 'title.infobar.workflow.list',
					'state' : 'cda.workflow.wfSetup.list',
					'params' : {}
				}, {
					'name' : 'title.infobar.currency.list',
					'state' : 'cda.currency.list',
					'params' : {}
				}]
			});
		}

		function cancelFailed(response) {
			modalService.openErrorDialogs({
				'messages' : response.error
			});
		}		
	}
})(angular);